package com.zixun.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.itheima.loopviewpager.LoopViewPager;
import com.zixun.Models.Message;
import com.zixun.Models.MessageItem;
import com.zixun.R;
import com.zixun.activity.DoctorDetailActivity;
import com.zixun.adapter.DoctorAdapter;
import com.zixun.db.DatabaseUtil;


import java.util.ArrayList;
import java.util.List;


/**
 * 作者：郭郭
 * 我们
 */
public class DoctorFragment extends Fragment {
    private RecyclerView recyclerView;

    private List<MessageItem> datas;
    private DoctorAdapter adapter;

    private LoopViewPager loopViewPager;
    private TextView center_text;
    private DatabaseUtil mUtil;
    private List<Message> list = null;

    public DoctorFragment() {
    }

    public DoctorFragment(Context context) {
        initData(context);
    }


    @Nullable
    @Override
    public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.doctor_fragment, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.rlv_content);
        center_text = (TextView) view.findViewById(R.id.center_text);
        center_text.setText("咨询者");
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(linearLayoutManager);
        adapter = new DoctorAdapter(getContext(), datas);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new DoctorAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, String data) {
                //  Toast.makeText(getContext(),"position"+position,Toast.LENGTH_LONG).show();
                Intent intent = new Intent(getActivity(), DoctorDetailActivity.class);
                intent.putExtra("tag", position + "");
                startActivity(intent);
            }
        });

        return view;
    }

    private void initData(Context context) {
        datas = new ArrayList<>();
        mUtil = new DatabaseUtil(context);
        list = mUtil.queryAll1();
        for (int i = 0; i < 5; i++) {
            MessageItem item = new MessageItem();
            switch (i) {
                case 0:
                    item.setContent(list.get(i).getTitle());
                    item.setImageId(R.mipmap.person1);
                    datas.add(item);

                    break;
                case 1:
                    item.setContent(list.get(i).getTitle());
                    item.setImageId(R.mipmap.person2);
                    datas.add(item);
                    break;
                case 2:
                    item.setContent(list.get(i).getTitle());
                    item.setImageId(R.mipmap.person3);
                    datas.add(item);
                    break;
                case 3:
                    item.setContent(list.get(i).getTitle());
                    item.setImageId(R.mipmap.person4);
                    datas.add(item);
                    break;
            }
        }
    }
}
